package com.wx.freemarker;

import java.util.List;

import com.wx.service.impl.SpringContextHolder;

import freemarker.template.SimpleScalar;
import freemarker.template.TemplateMethodModelEx;
import freemarker.template.TemplateModelException;

/**
 * 自定义标签创建器
 */
public class TagCreator implements TemplateMethodModelEx {

	@SuppressWarnings("rawtypes")
	public Object exec(List args) throws TemplateModelException {
		SimpleScalar args1 = (SimpleScalar) args.get(0);
		String beanid = args1.getAsString();
		
		if (beanid==null || beanid.isEmpty() || !beanid.equals(beanid.trim())) {
			throw new TemplateModelException("标签beanid参数不正确,请检查");
		}
		
		return SpringContextHolder.getBean(beanid);
//		ConfigurableApplicationContext applicationContext = (ConfigurableApplicationContext) SpringContextHolder .getApplicationContext();
//		return applicationContext.getBean(beanid);
	}

}
